<template>
  <div>
    <p0>我的收藏/收藏公司</p0>
    <div1>
  <el-table
    :data="this.companyList"
    header-cell-style="{background:'#eef1f6',color:'#606266'}"
    :row-style="{height:'50px',fontSize:'18px',color:'#666',fontFamily:'MicrosoftYaHeiUI'}"
    style="width: 100%">

    <el-table-column
      label="序号"
      prop="ordno_CompanyCol"
      type="index"
      width="300"
      align="left">
    </el-table-column>
    <template v-for="item in tableLabel">
            <el-table-column
              :key="index"
              :prop="item.prop"
              :label="item.label"
              :width="item.width"
              :align="item.align">
            </el-table-column>
          </template>
    <!--<el-table-column
      label="公司名称"
      prop="eid"
      width="750">
      <template slot-scope="scope">
        <span style="margin-left: 10px">{{ scope.row.companyName }}</span>
      </template>
    </el-table-column>-->
    <el-table-column
      label="公司ID"
      prop="eid"
      v-if="show"
      align="left">
    </el-table-column>
    <el-table-column
      label="操作"
      width="200"
      align="center">
      <template slot-scope="scope">
        <el-button
          size="mini"
          type="danger"
          @click="handleDelete(scope.$index, scope.row)">取消收藏</el-button>
      </template>
    </el-table-column>
  </el-table>
  </div1>
    <el-pagination
        background
        :page-sizes="this.page.pageSizes"
        :page-size="this.page.pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        @size-change="sizeChange"
        @current-change="currentChange"
        :total="this.page.total"
        class="page">
  </el-pagination>
  </div>
</template>

<script>
import fetch from '../api/fetch'
  export default {
    name:'app',
    mounted() {
    //this.loadData(),
      this.getStuCollect({
        pageNum:1,
        pageSize:20,
        StuCollect:{
          sid:sessionStorage.getItem('userId')
        }
      });
    },
    data() {
      return {
        show:false,
        companyList:[],
        tableLabel:[
        {prop:"Entname", label:"公司名称",width:"400",align:"left"},
      ],
        page:{
        pageSize:10,
        currentPage:1,
        pageSizes:[5,10,20,30,50],
        total:0
        }
      }
    },
    methods: {
      getStuCollect(StuCollect) {
        fetch.getStuCollect(StuCollect).then(res => {
          console.log(res)
          for (var i=0; i<res.data.rows.length; i++)
        {
          this.companyList.push({
            Entname: res.data.rows[i].ename,
          })
        }
            this.page.currentPage = res.data.page
            this.page.total = res.data.total

        })
      },
      handleDelete (index, row) {
      console.log(index, row);
      this.$confirm('取消收藏, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.$message({
          type: 'success',
          message: '取消收藏成功!'
        });
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消'
        })
      })
    },
      handleEdit(index, row) {
        console.log(index, row);
      },
      setNewsApi: function() {
        this.$http.get("/companyDelete", "").then(res => {
          this.data = res.data.data;
        });
      },
      //每页数据条数改变事件
      sizeChange(pageSize){
        this.page.pageSize=pageSize
        this.loadData()
      },
      //当前页数据改变事件
      currentChange(currentPage){
        this.page.currentPage = currentPage
        this.loadData()
      },
      //数据加载事件
      loadData(){
        this.getStuCollect(this.page.currentPage, this.page.pageSize).then(res=>{
          //this.companyList=res.data.data
          this.page.total=res.data.total
        })
      },
      deleteList(data) { //删除数据
        let eid = data.eid;
        this.$http.post('/list', {
            params: {
              id: eid
            }
          }).then(function(res) {
            console.log(res);
            this.data = res.data.data;
            alert(data.name + '取消收藏成功');
          }.bind(this))
          .catch(function(error) {
            console.log(error)
          });
      }
    }
  }
</script>

<style scoped>
p0 {
  position: absolute;
  left: 250px;
  top: 75px;
  font-size: 14px;
  color: #909399
}
div1 {
  position: absolute;
  left: 275px;
  top: 120px;
  }
.page {
  position: absolute;
  left: 600px;
  bottom: 100px;
}
</style>

